package com.buanalintas.sandals.pos.sales;

import com.buanalintas.bynga.Dictionary;
import com.buanalintas.bynga.Field;
import com.buanalintas.bynga.Page;
import com.buanalintas.sandals.pos.entities.PosMasterSales;

public class Sales extends Page {

    private Field salesId;
    private Field salesName;
    private Field salesUnitId;
    private Field salesPlaceOfBirth;
    private Field salesDateOfBirth;
    private Field salesAddress;
    private Field salesPhone;
    private Field salesEmail;

    public Sales() {
        setTheClass(PosMasterSales.class);

        salesId = new Field();
        salesId.setName("salesId");
        salesId.setCaption("id");
        salesId.setListProperties(" align=\"center\" width=\"7%\" nowrap");
        salesId.setInputProperties(" size=\"20\"");
        getFields().add(salesId);

        salesName = new Field();
        salesName.setName("salesName");
        salesName.setCaption("name");
        salesName.setDummy(true);
        salesName.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        salesName.setInputProperties(" size=\"15\"");
        salesName.setRequired(true);
        salesName.setInputCase(Field.CASE_UPPER);
        getFields().add(salesName);
        
        salesUnitId = new Field();
        salesUnitId.setName("salesUnitId");
        salesUnitId.setCaption("unit");
        salesUnitId.setListProperties(" align=\"center\" width=\"20%\" nowrap");
        salesUnitId.setInputProperties(" ");
        salesUnitId.setInputType(Field.INPUT_COMBO_BOX);
        salesName.setRequired(true);
        getFields().add(salesUnitId);

        salesPlaceOfBirth = new Field();
        salesPlaceOfBirth.setName("salesPlaceOfBirth");
        salesPlaceOfBirth.setCaption("place of birth");
        salesPlaceOfBirth.setListProperties(" align=\"left\" width=\"12%\" nowrap");
        salesPlaceOfBirth.setInputProperties(" size=\"20\"");
        salesPlaceOfBirth.setRequired(true);
        salesPlaceOfBirth.setInputCase(Field.CASE_UPPER);
        getFields().add(salesPlaceOfBirth);

        salesDateOfBirth = new Field();
        salesDateOfBirth.setName("salesDateOfBirth");
        salesDateOfBirth.setCaption("date of birth");
        salesDateOfBirth.setListProperties(" align=\"center\" width=\"5%\" nowrap");
        salesDateOfBirth.setInputProperties(" size=\"20\"");
        salesDateOfBirth.setRequired(true);
        salesDateOfBirth.setInputCase(Field.CASE_UPPER);
        getFields().add(salesDateOfBirth);

        salesAddress = new Field();
        salesAddress.setName("salesAddress");
        salesAddress.setCaption("address");
        salesAddress.setListProperties(" align=\"left\" width=\"25%\" nowrap");
        salesAddress.setInputProperties(" size=\"20\"");
        salesAddress.setRequired(true);
        salesAddress.setInputCase(Field.CASE_UPPER);
        getFields().add(salesAddress);

        salesPhone = new Field();
        salesPhone.setName("salesPhone");
        salesPhone.setCaption("phone");
        salesPhone.setListProperties(" align=\"right\" width=\"8%\" nowrap");
        salesPhone.setInputProperties(" size=\"30\"");
        salesPhone.setRequired(true);
        salesPhone.setInputCase(Field.CASE_UPPER);
        getFields().add(salesPhone);

        salesEmail = new Field();
        salesEmail.setName("salesEmail");
        salesEmail.setCaption("email");
        salesEmail.setListProperties(" align=\"left\" width=\"15%\" nowrap");
        salesEmail.setInputProperties(" size=\"20\"");
        salesEmail.setRequired(true);
        salesEmail.setInputCase(Field.CASE_UPPER);
        getFields().add(salesEmail);

        fillFields();

        getFieldsUnique().add(new Field[]{salesName});
        getFieldsAdd().remove(salesId);
        getFieldsEdit().remove(salesId);
        getFieldsList().remove(salesId);
        setExportList(getClass().getResourceAsStream("SalesList.jasper"));
        setExport(getClass().getResourceAsStream("Sales.jasper"));

        getController().setOrder(salesId);
    }
    
    @Override
    public void beforeExport() {
        getExportParams().put("title", Dictionary.getValue(this, "salesName"));
    }

    @Override
    public void beforeExportMulti() {
        beforeExport();
    }
}
